package com.guxingke.gblog.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.guxingke.gblog.dmo.Msg;
import com.guxingke.gblog.dto.MsgDto;
import com.guxingke.gblog.service.MsgService;
import com.guxingke.gblog.service.impl.MsgServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class MsgManageAction extends ActionSupport implements
		ServletRequestAware {
	private static final long serialVersionUID = 1L;
	private HttpServletRequest request;
	private MsgService msgService = new MsgServiceImpl();
	private List<MsgDto> msgs;
	private String mainPage;

	public List<MsgDto> getMsgs() {
		return msgs;
	}

	public void setMsgs(List<MsgDto> msgs) {
		this.msgs = msgs;
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}

	@Override
	public String execute() throws Exception {
		msgs = msgService.getAll();
		mainPage = "template/msg/manage-list.jsp";
		return SUCCESS;
	}

	public String delete() throws Exception {
		String msgId = request.getParameter("msgId");
		msgService.deleteMsg(Integer.parseInt(msgId));
		msgs = msgService.getAll();
		mainPage = "template/msg/manage-list.jsp";
		return "otherSuccess";
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
}
